package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    @ApiOperation("获取所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        return ResponseResult.success(deviceService.allProduct());
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.RegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询设备")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> deviceVoPageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(deviceVoPageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("查询设备详情")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest) {
        DeviceVo deviceVo = deviceService.QueryDeviceDetail(queryDeviceDetailRequest);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查询物模型数据")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest queryThingModelPublishedRequest) {
        return ResponseResult.success(deviceService.QueryThingModelPublished(queryThingModelPublishedRequest));
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation("更新设备信息")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult DeleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest) {
        deviceService.deleteDevice(deleteDeviceRequest);
        return ResponseResult.success();
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询设备属性状态")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest queryDevicePropertyStatusRequest) {

        return ResponseResult.success(deviceService.queryDevicePropertyStatus(queryDevicePropertyStatusRequest));
    }

}